
 function ListNode(val, next) {
     this.val = (val===undefined ? 0 : val)
    this.next = (next===undefined ? null : next)
  }
 lists = [[1,4,5],[1,3,4],[2,6]]
var mergeKLists = function(lists) {
   if(lists.length===0)return null
   let result=null
   for(const list of lists)
   {
      const dummy=new ListNode(0)
      let curr=dummy
      let p1= result
      let p2= list
      while(p1&&p2)
      {
        if(p1.val<p2.val)
        {
            curr.next=p1
            p1=p1.next
        }
        else{
            curr.next=p2
            p2=p2.next
        }
        curr=curr.next
      }
      if(p1)curr.next=p1
      if(p2)curr.next=p2
      result=dummy.next
   }
   
   return result


};
console.log(mergeKLists(lists));
